package com.xuecheng.learning.feignclient;

import com.xuecheng.base.model.RestResponse;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @author 26455
 * @version 1.0
 * @description TODO
 * @date 2023/2/28 11:15
 */
@FeignClient(value = "media-api", fallbackFactory = MediaServiceClient.MediaServiceClientFallbackFactory.class)
public interface MediaServiceClient {

    @GetMapping("/media/open/preview/{mediaId}")
    public RestResponse<String> getPlayUrlByMediaId(@PathVariable("mediaId") String mediaId);

    @Component
    class MediaServiceClientFallbackFactory implements FallbackFactory<MediaServiceClient> {

        @Override
        public MediaServiceClient create(Throwable throwable) {
            return new MediaServiceClient() {
                @Override
                public RestResponse<String> getPlayUrlByMediaId(String mediaId) {
                    return null;
                }
            };
        }
    }
}
